package com.essc.controller;

import com.essc.pojo.Message;
import com.essc.service.MessageService;
import com.essc.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@CrossOrigin
@RestController
public class MessageController {
    @Autowired
    private MessageService messageService;

    /*查找留言 商品详情页面底部显示所有用户在该商品下的所有留言*/
    @GetMapping("/findGoodMessage/{gid}/{uid}/{pageNum}/{pageSize}")
    public JsonResult findGoodMessage(@PathVariable("gid") Integer gid,
                                      @PathVariable("uid") Integer uid,
                                      @PathVariable("pageNum") Integer pageNum,
                                      @PathVariable("pageSize") Integer pageSize){
        return messageService.findGoodMessage(gid,uid,pageNum,pageSize);
    }

    /*根据uid查找留言 用户个人模块*/
    @GetMapping("/selectMessage")
    public JsonResult selectMessage(@RequestParam Integer uid) {
        return messageService.findMessageByUid(uid);
    }

    /*新增留言 用户在商品底下留言*/
    /*需要传入 userId goodId content*/
    @PostMapping("/addMessage")
    public JsonResult addMessage(@RequestBody Message message) {
        return messageService.addMessage(message);
    }

    /*根据留言id删除留言 用户个人模块实现*/
    @PostMapping("/delMessage/{mid}")
    public JsonResult delMessage(@PathVariable Integer mid) {
        return messageService.deleteMessageByMid(mid);
    }

}
